package com.sinbader.xiaole.admin.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.util.UserKit;
import cn.stylefeng.guns.sys.modular.enums.UserTypes;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import com.sinbader.xiaole.common.entity.ProductWarningMessage;
import com.sinbader.xiaole.common.model.params.ProductWarningMessageParam;
import com.sinbader.xiaole.common.service.ProductWarningMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 商品预警消息表控制器
 *
 */
@Api("商品预警消息表")
@Controller
@RequestMapping("/productWarningMessageShop")
public class ProductWarningMessageShopController extends BaseController {

    private String PREFIX = "/productWarningMessageShop";

    @Autowired
    private ProductWarningMessageService productWarningMessageService;

    /**
     * 跳转到主页面
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/productWarningMessageShop.html";
    }

    /**
     * 新增页面
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/productWarningMessageShop_add.html";
    }

    /**
     * 编辑页面
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/productWarningMessageShop_edit.html";
    }

    @ApiOperation(value = "新增")
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ProductWarningMessageParam productWarningMessageParam) {
        this.productWarningMessageService.add(productWarningMessageParam);
        return ResponseData.success();
    }

    @ApiOperation(value = "编辑")
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ProductWarningMessageParam productWarningMessageParam) {
        this.productWarningMessageService.update(productWarningMessageParam);
        return ResponseData.success();
    }

    @ApiOperation(value = "删除")
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ProductWarningMessageParam productWarningMessageParam) {
        this.productWarningMessageService.delete(productWarningMessageParam);
        return ResponseData.success();
    }

    @ApiOperation(value = "查看详情")
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ProductWarningMessageParam productWarningMessageParam) {
        ProductWarningMessage detail = this.productWarningMessageService.getById(productWarningMessageParam.getId());
        return ResponseData.success(detail);
    }

    @ApiOperation(value = "查询列表")
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ProductWarningMessageParam productWarningMessageParam) {
        productWarningMessageParam.setType(UserTypes.Shop);
        User user = UserKit.getUser();
        if (user.getType().equals(UserTypes.Shop)){
            productWarningMessageParam.setOrgId(user.getOrgId());
        }
        return this.productWarningMessageService.findPageBySpec(productWarningMessageParam);
    }

    @ApiOperation(value = "总部发货到门店")
    @ResponseBody
    @RequestMapping("/groupSendProduct")
    public ResponseData groupSendProduct(@RequestBody List<Long> ids) {
        this.productWarningMessageService.sendProduct(ids,UserTypes.Shop);
        return ResponseData.success();
    }

}
